<?php
$m = $_SESSION['m'];
if ($m == 1) {
$cid = $_SESSION['cid'];
$cartInfo = $soap->call ($session_id, 'cart.info', $cid);
// echo print_r($cartInfo);
$items = $cartInfo['items'];
$num_items = sizeof($items);
echo <<< HERE
			<table rules="cols" border="2" cellpadding="10">
				<thead>
					<tr>
						<th width="150"><u>Product Name</u></th>
						<th width="50"><u>Price</u></th>
						<th width="50"><u>Qty</u></th>
						<th width="150"><u>Total Price</u></th>
					</tr>
				</thead>
				
HERE;
echo 			"<tbody style=\"margin-top:10px\">";
echo				"<tr><td colspan=\"4\">&nbsp;</td></tr>";
$total = 0;
for ($i = 0; $i < $num_items; $i++) {
$pid = $items[$i]['product_id'];
$product = $soap->call ($session_id, 'catalog_product.info', $pid);
echo 				"<tr>";
echo					"<td>".$items[$i]['name']."</td>";
echo					"<td>$".number_format($product['price'], 2, '.', ',')."</td>";
echo					"<td>".$items[$i]['qty']."</td>";
echo					"<td>$".number_format($product['price']*$items[$i]['qty'], 2, '.', ',')."</td>";
$total += number_format($product['price']*$items[$i]['qty'], 2, '.', ',');
echo				"<tr>";
}
echo				"<tr><td colspan=\"4\">&nbsp;</td></tr>";
$_SESSION['total'] = $total;
echo			"</tbody>";
echo 			"<tfoot>";
echo				"<tr>";
echo					"<td><b>Total</b></td>";
echo					"<td colspan=\"2\"></td>";
echo					"<td align=\"right\"><b>$$total</b></td>";
echo				"</tr>";
echo			"</tfoot>";
echo		"</table>";
} else {
	$cart_array = $_SESSION['cart_array'];
	// echo print_r($cart_array);
	echo "<table border='2'>";
	echo 	"<thead>";
	echo		"<tr>";
	echo			"<th width='120'><u>Product Name</u></th>";
	echo			"<th width='80'><u>Price</u></th>";
	echo			"<th width='50'><u>Qty</u></th>";
	echo			"<th width='150'><u>Total Price</u></th>";
	echo		"</tr>";
	echo	"</thead>";
	echo	"<tbody>";
	echo		"<tr><td colspan=\"4\">&nbsp;</td></tr>";
	$total = 0;
	$num_item = sizeof($cart_array);
	for ($i = 0; $i < $num_item; $i++) {
		$prod_name = $cart_array[$i]['pname'];
		$prod_price = $cart_array[$i]['price'];
		$prod_qty = $cart_array[$i]['qty'];
		$prod_total = $cart_array[$i]['total'];
		echo 	"<tr>";
		echo		"<td>$prod_name</td>";
		echo		"<td>$$prod_price</td>";
		echo		"<td>$prod_qty</td>";
		echo		"<td>$prod_total</td>";
		echo	"</tr>";
		$total += $prod_total;
	}
	echo		"<tr><td colspan=\"4\">&nbsp;</td></tr>";
	echo	"</tbody>";
	echo 	"<tfoot>";
	echo		"<tr>";
	echo			"<td><b>Total</b></td>";
	echo			"<td colspan=\"2\"></td>";
	echo			"<td align=\"right\"><b>$$total</b></td>";
	echo		"</tr>";
	echo	"</tfoot>";
	echo "</table>";
	$_SESSION['total'] = $total;
}
?>